// 引入 models
const { paginationDefine } = require('../utils/router-helper');
const models = require('../models');
let taotaoItem = {
    method: 'GET',
    path: '/taotao/itemPage',
    handler: async (request, reply) => {
        const { rows: results, count: totalCount } = await models.tb_item.findAndCountAll({
            limit: request.query.limit,
            offset: (request.query.page - 1) * request.query.limit
        });
        // 开启分页的插件，返回的数据结构里，需要带上result与totalCount两个字段
        reply({ results, totalCount });
    },
    config: {
        tags: ['api'],
        description: '获取商品列表',
        validate: {
            query: {
                ...paginationDefine
            }
        },
        auth: false // 关闭jwt认证
    }
}
module.exports = [taotaoItem];
